package ro.upt.dcda.web;

import java.util.Map;

import ro.upt.dcda.pricezone.s1.pojo.User;
import ro.upt.dcda.pricezone.s1.requests.LogoutRequest;

import com.opensymphony.xwork2.ActionContext;

public class LogoutServlet {

	public String execute() throws Exception {
		Map<String, Object> session = ActionContext.getContext().getSession();
		User user = (User) session.get("user");
		String sid = (String) session.get("sid");
		if (user == null || sid == null) {
			System.out.println("Invalid logout requested");
			return "def";
		}
		LogoutRequest logout = new LogoutRequest();
		if (logout.work(user.getEmail(), sid)) {
			session.remove("user");
			session.remove("sid");
			session.remove("email");
			System.out.println("Succesful logout 2");
		} else {
			System.out.println("Failed logout");
		}
		return "def";
	}
}
